
/*
 *
 * Required to use mootools framework
 *
 **/
var InterfaceController = new Class(
{
	initialize: function()
	{
		//this.playerStatusDiv = $('playerStatusDiv');
		this.playerStatusDiv = window.document.getElementById('playerStatusDiv');
		this.players 		 = Player.initPlayers();
		this.areas			 = Area.initAreas();
		this.armiesInArea	= new Array();
	},
	updatePlayerStatus: function()
	{
		
	}
});

/*
 *
 * Player class
 *
 **/
var Player = new Class(
{
	initialize: function(name, numberOfArmies, numberOfCards, numberOfLands)
	{
		this.name 			= name;
		this.numberOfArmies = numberOfArmies;
		this.numberOfCards	= numberOfCards;
		this.numberOfLands	= numberOfLands;
	},
});

Player.initPlayers = function()
{
	printf(playersJSON);
	var players = new Array();
	for ( var player in playersJSON )
	{
		players.push(new Player(
			player.name, 
			player.numberOfArmies,
			player.numberOfCards,
			player.numberOfLands
		));
	}
	//self.interfaceController.players = players;
	return players;
};



/*
 *
 * Area class
 *
 **/
var Area = new Class(
{
	initialize: function(dom, name, numberOfArmies)
	{
		this.numberOfArmies = numberOfArmies;
		this.name 			= name;
		this.dom 			= dom;
		interfaceController.armiesInArea[this.name] = 0;
		this.dom.addEventListener("click", this.addArmy, false);
	},
	addArmy: function(self)
	{
		printf(this.title);
		printf(++interfaceController.armiesInArea[this.title]);
		//printf(self);
		//self.numberOfArmies++;
		//printf(self.name + "have " + self.numberOfArmies + " armies");
	}
});

Area.initAreas = function()
{
	printf("initAreas");
	var areas = window.document.getElementsByTagName('area');
	
	var tempAreaArray = new Array();
	for ( var i = 0; i < areas.length; i++)
	{
		var domArea = areas[i];
		/*
		area.addEventListener("click", addArmy, false);
		var key = area.title;
		areasArmy[key] = 0;
		*/
		var name = domArea.title;
		tempAreaArray.push(new Area(domArea, name, 0));
	}

	return tempAreaArray;
}









/*
 *
 * Standard javascript below
 *
 */
var areasArmy = new Array();
var attachClickEvent = function()
{
	printf("attachClickEvent");
	var areas = window.document.getElementsByTagName('area');


	for ( var i = 0; i < areas.length; i++)
	{
		var area = areas[i];
		area.addEventListener("click", addArmy, false);
		var key = area.title;
		areasArmy[key] = 0;
		//printf("areasArmy['" + key +  "'] = " + areasArmy[key]);
	}
};

/*
var addArmy = function(e)
{
	var area = e.currentTarget;
	var key = area.title;
	printf("areasArmy[" + key + "] = " + ++areasArmy[key]);
};

*/


/**
 *
 * runs after window.onload
 *
 **/
var interfaceController;
var self = this;
window.onload = function()
{
	var img = window.document.getElementById('index');
   	img.className = "mapper noborder";
	//printf(img);

	//attachClickEvent();
	self.interfaceController = new InterfaceController();
	//Player.initPlayers();
};

